package com.itzmn.java.javase.designpattern.proxy.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Author: 张梦楠
 * @Date: 2018/12/1 14:15
 * 简书：https://www.jianshu.com/u/d611be10d1a6
 * 码云：https://gitee.com/zhangqiye
 * @Description:
 */
public class MeiPo implements InvocationHandler {

    private Person person;
    public Object getinstace(Person person){
        // 将被代理类保存，用于下面的调用
        this.person = person;
        return Proxy.newProxyInstance(person.getClass().getClassLoader(),person.getClass().getInterfaces(),this);
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("说出你的要求");
        method.invoke(this.person,args);
        System.out.println("开始为你选择");
        return null;
    }
}
